package com.tedu.api.io;

import org.junit.Test;

import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class homework1 {
    //1.空指针异常
    public static void main(String[] args) {
        String str=null;
        try{
            System.out.println(str.length());
        }catch
        (NullPointerException e){
            System.out.println("发生空指针：");
        }
        //2.数字格式化异常
        try{
            String str9="abc";
            int num=Integer.parseInt(str9);
            System.out.println("数字"+num);
        }catch
        (NumberFormatException e){
            System.out.println("数字格式化"+e.getMessage());
        }
        //3.数组越界异常
        int[]arr =new int[3];
        try{
            System.out.println(arr[3]);
        }catch
        (ArrayIndexOutOfBoundsException e){
            System.out.println("越界异常"+e.getMessage());
        }
        //4.文件未找到异常
        try{
            FileInputStream fis=new FileInputStream("b.txt");
        }catch
        (FileNotFoundException e){
            System.out.println("文件未找到"+e.getMessage());
        }
        //5.类型转化异常
        try{
            Object obj=new Object();
            String str2=(String) obj;
            System.out.println("转换后字符"+str2);


        }catch(ClassCastException e){
            System.out.println("类型转换"+e.getMessage());
        }
    }
}
